package com.mt.operation.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.operation.api.service.ISearchKeywordsService;
import com.mt.operation.entity.SearchKeywordsEntity;
import com.mt.operation.service.model.SearchKeywordsServiceModel;

@Service
public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SearchKeywordsServiceImpl.class);

    @Autowired
    private SearchKeywordsServiceModel searchKeywordsServiceModel;

    public ServiceResult<SearchKeywordsEntity> findInfo(Map<String, Object> params) {
        ServiceResult<SearchKeywordsEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = searchKeywordsServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<SearchKeywordsEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<SearchKeywordsEntity>> result = new ServiceResult<List<SearchKeywordsEntity>>();
        try {
            result = searchKeywordsServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(SearchKeywordsEntity searchKeywordsEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.insert(searchKeywordsEntity);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(SearchKeywordsEntity searchKeywordsEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.updateByPrimaryKeySelective(searchKeywordsEntity);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer searchKeywordsId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.deleteByPrimaryKey(searchKeywordsId);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> insertList(List<SearchKeywordsEntity> list) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.insertList(list);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][insertList]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> deleteList(ArrayList<Integer> list) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.deleteList(list);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][insertList]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> updateList(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = searchKeywordsServiceModel.updateList(params);
        } catch (Exception e) {
            LOGGER.error("[ISearchKeyWordsServiceImpl][insertList]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }
}
